Javascript Overview

  • Javascript Output :

    We have following ways through that we can display the output from javascript

    1. document.getElementById("demo").innerHTML = 1+0; property of innerHTML of HTML to display the data..
    2. document.write("Pavan"); will be using for testing
    3. <button type="button" onclick="document.write('Pavan')"> it will delete all the html and show the output
    4. window.alert("Pavan"); //to show data in alert
    5. console.log("Pavan"); //Debuging purpose

    Instructions:

    Programming is nothing but the instrcution given by us to machine.
    insruction are in the form of statements
    javascript is nothing but list of statements eecuted from top to bottom

    Statements contains: values,expressions,operators,comments and keywords.

    Semicolon is used to indentify the end of statement.
    we can break the line after operator.

     

    Keywords:

    1. break
    2. continue
    3. debugger
    4. do..while
    5. for
    6. function
    7. if..else
    8. return
    9. switch
    10. try..catch
    11. var  :tells the browser to create a variable

    Syntax

    We have 2 types of values i.e.
    1.Literals (hardcoded value or constant value)
    2.Values (varible values)

    its a case sensetaive..

    Var, VAR and var is different

    Lastname and lastname are different.

    var y;
    var f,g,h;

    f=g+h;
    g="P"+"a";

    Variables:

    Variables are for storing the data value.
    Variables must be unique.

    Variables created without the keyword var, are always global.

    Variable Rules:
    Names can contain letters, digits, underscores, and dollar signs.
    Names must begin with a letter
    Names can also begin with $ and _ (but we will not use it in this tutorial)
    Names are case sensitive (y and Y are different variables)
    Reserved words (like JavaScript keywords) cannot be used as names

    A variable declared without a value will have the value undefined.

    2 types of Variables
    1.Local Variable : can be access withing the block
    2.Global Variable : can access through out the page

    Operators:

    = is the assignment operator and == is the equal operator

    ++ increment

    -- decrement

    null === undefined // false
    null == undefined //true

    () operator invokes the function

    Notes:
    function without () will return the function definition instead of the function result

    Data Type:

    Primitive Data Type (normal data types which are without properties and methods)

    String
    Number
    Bolean
    Undefined
    Null

    Non Primitive Data Types:

    Object
    Array
    RegExp

    typeof undefined // undefined
    typeof null // object

    Function: for reusability of code

    We invoke the function on

    1. any event occurs (on click of user)
    2. () from JavaScript code
    3. Automatically (self invoked)

     

    Events:

    1. onchange
    2. onclick
    3. onmouseover
    4. onmouseout
    5. onkeydown
    6. onload

    Object:

    var training = {
    trainername: "Abel",
    skill : "Servicenow",
    id : 111,
    trainerwithskill : function() {
    return this.trainername + " " + this.trainername;
    }
    };

    var t=training.trainerwithskill(); //function value
    var t=training.trainerwithskill; //function defination
    var t=training.skill;
    var t=training["skill"];